package com.runda.controller.delivery;

import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bbjob.dto.Result;
import com.bbjob.model.QueChoice;
import com.bbjob.model.QueOperation;
import com.bbjob.model.QuestionBank;
import com.runda.service.IQuestionBankService;
import com.runda.util.DataEntity;

@Api(tags = "questionbankApi-delivery", description = "题库管理(分发中心用绕过登录)")
@RestController
@RequestMapping(path = "delivery/questionbank", produces = "application/json;charset=utf-8")
public class DeliveryQuestionBankController {

	@Resource
	private IQuestionBankService questionBankService;

	@ApiOperation(value = "查询题库", notes = "根据考试id查询题库列表")
	@RequestMapping(value = "getListByExamId/{id}", method = RequestMethod.GET)
	public Result getListByExamId(@PathVariable("id") Integer id) {

		List<QuestionBank> list = questionBankService.selectByExamId(id);

		return new Result(list);
	}

	@ApiOperation(value = "查询试卷", notes = "根据组织机构识别码查询题库列表")
	@ApiImplicitParam(name = "bank", value = "试卷信息", required = true, dataType = "QuestionBank")
	@RequestMapping(value = "all", method = RequestMethod.POST)
	public Result getListByExamId(@RequestBody QuestionBank bank) {

		List<QuestionBank> list = questionBankService.selectByParams(bank);

		return new Result(list);
	}

	/**
	 * 获取私有试卷(根据userid获取相应权限)
	 * 
	 * @param name
	 *            试卷名字过滤
	 * @param userid
	 *            用户id
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取私人试卷", notes = "获取私人试卷")
	@RequestMapping(value = "getBank", method = RequestMethod.GET)
	public DataEntity getBank(Integer type, String name, Integer difficulty, Integer userid,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size) {
		return DataEntity.getInstance(questionBankService.getBank(type, name, difficulty, userid, page, size));
	}

	/**
	 * 获取公共试卷
	 * 
	 * @param name
	 *            试卷名字过滤
	 * @param userid
	 *            用户id
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取系统公共试卷", notes = "获取系统公共试卷")
	@RequestMapping(value = "getFreeBank", method = RequestMethod.GET)
	public DataEntity getFreeBank(Integer type, String name, Integer difficulty,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size) {
		return DataEntity.getInstance(questionBankService.getFreeBank(type, name, difficulty, page, size));
	}

	/**
	 * 获取客观题私有题库(根据userid获取权限)
	 * 
	 * @param name
	 *            题干
	 * @param userid
	 *            用户id
	 * @param type
	 *            1选择2判断
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取客观题私有题库", notes = "获取主观题私有题库")
	@RequestMapping(value = "getChoice", method = RequestMethod.GET)
	public DataEntity getChoice(String bankid, String tag, String name, Integer type, Integer userid,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size, Integer bankType) {
		return DataEntity
				.getInstance(questionBankService.getChoice(bankid, tag, name, type, userid, page, size, bankType));
	}

	/**
	 * 获取客观题公共题库(根据userid获取权限)
	 * 
	 * @param name
	 *            题干
	 * @param userid
	 *            用户id
	 * @param type
	 *            1选择2判断
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取客观题公共题库", notes = "获取主观题公共题库")
	@RequestMapping(value = "getFreeChoice", method = RequestMethod.GET)
	public DataEntity getFreeChoice(String bankid, String tag, String name, Integer type, Integer userid,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size, Integer bankType) {
		return DataEntity
				.getInstance(questionBankService.getFreeChoice(bankid, tag, name, type, userid, page, size, bankType));
	}

	/**
	 * 获取主观题私有题库(根据userid获取权限)
	 * 
	 * @param name
	 *            题干
	 * @param type
	 *            题目类型
	 * @param userid
	 *            用户id
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取主观题私有题库", notes = "获取主观题公共题库")
	@RequestMapping(value = "getOperation", method = RequestMethod.GET)
	public DataEntity getOperation(String bankid, String tag, String name, Integer type, Integer userid,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size) {
		return DataEntity.getInstance(questionBankService.getOperation(tag, bankid, name, type, userid, page, size));
	}

	/**
	 * 获取主观题公共题库(根据userid获取权限)
	 * 
	 * @param name
	 *            题干
	 * @param type
	 *            题目类型
	 * @param userid
	 *            用户id
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation(value = "获取主观题公共题库", notes = "获取主观题公共题库")
	@RequestMapping(value = "getFreeOperation", method = RequestMethod.GET)
	public DataEntity getFreeOperation(String bankid, String tag, String name, Integer type, Integer userid,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int size) {
		return DataEntity.getInstance(questionBankService.getOperation(tag, bankid, name, type, userid, page, size));
	}

	/**
	 * 根据客观题ID获取详细信息
	 * 
	 * @param Choiceid
	 * @return
	 */
	@ApiOperation(value = "根据客观题ID获取详细信息", notes = "获取主观题私有题库")
	@RequestMapping(value = "getItemByChoiceid", method = RequestMethod.GET)
	public DataEntity getItemByChoiceid(String Choiceid) {
		return DataEntity.getInstance(questionBankService.getItemByChoiceid(Choiceid));
	}

	/**
	 * 根据试卷id获取客观题
	 * 
	 * @param Choiceid
	 * @return
	 */
	@ApiOperation(value = "根据试卷id获取客观题", notes = "根据试卷id获取客观题")
	@RequestMapping(value = "getChoiceByBank", method = RequestMethod.GET)
	public DataEntity getChoiceByBank(QueChoice choice, @RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int rows) {
		return DataEntity.getInstance(questionBankService.getChoiceByBank(choice, page, rows));
	}

	/**
	 * 根据试卷id获取主观题
	 * 
	 * @param operation
	 * @param page
	 * @param rows
	 * @return
	 */
	@ApiOperation(value = "根据试卷id获取主观题", notes = "根据试卷id获取主观题")
	@RequestMapping(value = "getOperationByBank", method = RequestMethod.GET)
	public DataEntity getOperationByBank(QueOperation operation,
			@RequestParam(required = false, defaultValue = "1") int page,
			@RequestParam(required = false, defaultValue = "10") int rows) {
		return DataEntity.getInstance(questionBankService.getOperationByBank(operation, page, rows));
	}
	
	/**
	 * 根据客观题id获取解析
	 * 
	 * @param operation
	 * @param page
	 * @param rows
	 * @return
	 */
	@ApiOperation(value = "根据客观题id获取解析", notes = "根据客观题id获取解析")
	@RequestMapping(value = "getChoiceAnalysis", method = RequestMethod.GET)
	public DataEntity getChoiceAnalysis(String id) {
		return DataEntity.getInstance(questionBankService.getChoiceAnalysis(id));
	}
	
	/**
	 * 根据主观题id获取解析
	 * 
	 * @param operation
	 * @param page
	 * @param rows
	 * @return
	 */
	@ApiOperation(value = "根据主观题id获取解析", notes = "根据主观题id获取解析")
	@RequestMapping(value = "getOperationAnalysis", method = RequestMethod.GET)
	public DataEntity getOperationAnalysis(String id) {
		return DataEntity.getInstance(questionBankService.getOperationAnalysis(id));
	}
}
